package com.shujia.mr.reduceJoin;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyReduceJoinReducer extends Reducer<Text,Text, NullWritable,Student> {
    @Override
    protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, NullWritable, Student>.Context context) throws IOException, InterruptedException {

        Student student = new Student();
        student.setStudentID(key.toString());
        for (Text value : values) {
            String valueStr = value.toString();
            String[] columns = valueStr.split(",");
            // 对Value信息进行判断
            if (columns.length == 4){
                student.setName(columns[0]);
                student.setAge(columns[1]);
                student.setGender(columns[2]);
                student.setClazz(columns[3]);
            }else {
                student.setScore(columns[0]);
            }
        }
        context.write(NullWritable.get(),student);
    }
}
